﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FluentStateObserver.Test
{
    /// <summary>
    /// A helper class allowing for passing in a dispose action.
    /// </summary>
    public class AnonymousDisposable : IDisposable
    {
        /// <summary>
        /// Gets or sets the dispose action.
        /// </summary>
        /// <value>The dispose action.</value>
        private Action DisposeAction { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="AnonymousDisposable"/> class.
        /// </summary>
        /// <param name="disposeAction">The dispose action.</param>
        public AnonymousDisposable(Action disposeAction)
        {
            DisposeAction = disposeAction;
        }

        #region IDisposable Members

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (DisposeAction != null)
                DisposeAction.Invoke();
        }

        #endregion
    }
}
